/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package maxent.mr.io;

import java.io.IOException;
import java.io.ObjectOutputStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

/**
 *
 * @author hadoop
 */
public class ObjectWriter {

    /*
     * Write object to HDFS
     * @param Configuration hadoop configuration
     * @param Object object to write
     * @param String path path to write to
     * @param String filename filename to write to
     *
     * @return String path where object written
     */
    public static Path write(Configuration conf, Object obj, String path, String filename) throws IOException{

        FileSystem fs = FileSystem.get(conf);
        Path temp = new Path(path,filename);
        System.out.println(temp.toString());
        ObjectOutputStream os = new ObjectOutputStream(fs.create(temp));
        os.writeObject(obj);
        os.close();
        System.out.println("Object written");
        return temp;
    }

}
